﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.BaseDoc.Model;
using Yipusoft.BaseDoc.BLL;
public partial class Task_BaseDoc_SearchKeys : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            init();
        }

    }
    void init()
    {
        ListPageContral1.SetFirstPage();
        BindDate();
    }

    private void BindDate()
    {
        string DepartmentId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        List<DocSearchKeyInfo> list = DocSearchKey.GetList("departmentid ='" + DepartmentId + "' order by CreateDate ");
        ListPageContral1.ItemCount = list.Count;
        DL.DataSource = list;
        DL.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtKeyWord.Text.Trim().Length > 0)
        {
            string DepartmentId = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
            DocSearchKeyInfo info = new DocSearchKeyInfo();
            info.CreartUser = User.Identity.Name;
            info.CreateDate = DateTime.Now;
            info.DepartmentId = DepartmentId;
            info.Id = Guid.NewGuid();
            info.KeyWord = txtKeyWord.Text;
            info.Sign = 0;
            DocSearchKey.Insert(info);
            init();
        }
        else
        {
            Promt.Text = "提示：填写不能为空！";
        }
    }
    protected void DL_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {

        DL.PageIndex = PageIndex;
        BindDate();
    }
    protected void DL_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            Guid Id = new Guid(e.CommandArgument.ToString());
            DocSearchKey.Delete(Id);
            BindDate();
        }
    }
}
